Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Alter .. RENAME SQL #146

Merged
merged 5 commits into from
Nov 11, 2019
Merged

Fix Alter .. RENAME SQL #146

merged 5 commits into from
Nov 11, 2019

Conversation

emin100
Copy link
Contributor

@emin100 emin100 commented Jul 1, 2019

ALTER TRIGGER "emp_stamp" ON "emp" RENAME TO "emp_track_chgs"

ALTER FUNCTION "sqrt"(int) RENAME TO "square_root"

ALTER MATERIALIZED VIEW "foo" RENAME TO "bar"

ALTER CONVERSION "iso_8859_1_to_utf8" RENAME TO "latin1_to_unicode"

ALTER DOMAIN "zipcode" RENAME CONSTRAINT zipchk TO "zip_check"

ALTER COLLATION "de_DE" RENAME TO "german"

ALTER AGGREGATE "myavg"(int) RENAME TO "my_average"

ALTER TABLE "distributors" RENAME COLUMN address TO "city"

ALTER TABLE "distributors" RENAME CONSTRAINT zipchk TO "zip_check"

ALTER TYPE "electronic_mail" RENAME TO "email"

ALTER INDEX "distributors" RENAME TO "suppliers"

ALTER TABLESPACE index_space RENAME TO "fast_raid"

ALTER TRIGGER "emp_stamp" ON "emp" RENAME TO "emp_track_chgs"

ALTER RULE notify_all ON "emp" RENAME TO "notify_me"

mehmet emin karakas added 3 commits July 1, 2019 14:26
CREATE DOMAIN us_postal_code AS TEXT
CHECK(
   VALUE ~ '^\d{5}$'
OR VALUE ~ '^\d{5}-\d{4}$'
);
`deparse_renamestmt': Can't deparse: {"renameType"=>47, "relationType"=>0, "relation"=>{"RangeVar"=>{"relname"=>"foo", "inh"=>true, "relpersistence"=>"p", "location"=>11}}, "newname"=>"bar", "behavior"=>0} (RuntimeError)

ALTER VIEW "foo" RENAME TO "bar"
`deparse_renamestmt': Can't deparse: {"renameType"=>47, "relationType"=>0, "relation"=>{"RangeVar"=>{"relname"=>"foo", "inh"=>true, "relpersistence"=>"p", "location"=>11}}, "newname"=>"bar", "behavior"=>0} (RuntimeError)

ALTER VIEW "foo" RENAME TO "bar"
output << deparse_item(node['relation'])
output << 'RENAME TO'
output << node['newname']
output << deparse_identifier(node['newname'], escape_always: true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify why we need to escape this one always?

I mostly added that as a legacy option to avoid breaking too many tests, but I think going forward this should not be used if we can avoid it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ALTER VIEW "foo" RENAME TO "Bar"
if execute this sql without (escape_always: true) options, deparser result is ALTER VIEW "foo" RENAME TO Bar. If you execute deparser sql, rename the view as a bar not Bar.
So we need this options.

mehmet emin karakas added 2 commits July 8, 2019 02:05
ALTER TRIGGER "emp_stamp" ON "emp" RENAME TO "emp_track_chgs"

ALTER FUNCTION "sqrt"(int) RENAME TO "square_root"

ALTER MATERIALIZED VIEW "foo" RENAME TO "bar"

ALTER CONVERSION "iso_8859_1_to_utf8" RENAME TO "latin1_to_unicode"

ALTER DOMAIN "zipcode" RENAME CONSTRAINT zipchk TO "zip_check"

ALTER COLLATION "de_DE" RENAME TO "german"

ALTER AGGREGATE "myavg"(int) RENAME TO "my_average"

ALTER TABLE "distributors" RENAME COLUMN address TO "city"

ALTER TABLE "distributors" RENAME CONSTRAINT zipchk TO "zip_check"

ALTER TYPE "electronic_mail" RENAME TO "email"

ALTER INDEX "distributors" RENAME TO "suppliers"

ALTER TABLESPACE index_space RENAME TO "fast_raid"

ALTER TRIGGER "emp_stamp" ON "emp" RENAME TO "emp_track_chgs"

ALTER RULE notify_all ON "emp" RENAME TO "notify_me"
@emin100 emin100 changed the title View Rename Problem Fix Alter .. RENAME SQL Aug 28, 2019
@lfittl lfittl merged commit 459bae0 into pganalyze:master Nov 11, 2019
@emin100 emin100 deleted the alter_rename branch December 28, 2020 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants